RandomGenerator   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 13
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 7
dl 0
loc 13
rs 10
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A generate 0 11 2
1
/* eslint-disable no-magic-numbers */
2
import crypto from 'crypto';
3
import Generator from './Base';
4
5
/**
6
 * Generates a random number from 0 to 1.
7
 * @returns {number} number
8
 * @generator
9
 */
10
export default class RandomGenerator extends Generator {
11
    generate() {
12
        const bytes = crypto.randomBytes(7);
13
14
        let randomValue = (bytes[0] % (2 ** 5)) / (2 ** 5);
15
16
        bytes.slice(1).forEach(byte => {
17
            randomValue = (randomValue + byte) / (2 ** 8);
18
        });
19
20
        return randomValue;
21
    }
22
}
23